package eu.dicode.analysis.demonstrator.util;

import eu.dicode.analysis.demonstrator.model.HomeCommand;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Properties;

/**
 * Populate a HomeCommand with available query strings.
 */
public final class CommandPopulator {

  private final Collection<String> queries = new ArrayList<String>();

  public CommandPopulator() throws IOException {
    // we ship this file, if it is not there we want to fail with some sort of runtime error
    InputStream stream = null;
    try {
      stream = this.getClass().getResourceAsStream("/dicode.analysis.demonstrator.properties");
      Properties props = new Properties();
      props.load(stream);
      String queryString = props.getProperty("eu.dicodeproject.analysis.histogram.queries");
      for (String query : queryString.split(":")) {
        this.queries.add(query);
      }
    } finally {
      if (stream != null) stream.close();
    }

  }
  public void populate(HomeCommand homeCommand) {
    homeCommand.setAllKnownQueries(this.queries);
  }
}
